package cq.com.cn.servlet;

import com.google.gson.JsonObject;
import cq.com.cn.model.UserModel;
import cq.com.cn.service.GoodsCardService;
import cq.com.cn.service.UserService;
import cq.com.cn.utils.AjaxUtils;
import cq.com.cn.utils.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/goodscard/saveGoods.do")
public class InsertGoodsCardServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String bookId=req.getParameter("bookId");
        //判断用户是否登录
        Object obj = req.getSession().getAttribute(Constants.SEESIONKEY);
        UserModel user= (UserModel) obj;
        GoodsCardService goodsCardService=new GoodsCardService();
        goodsCardService.saveGoodsCard(user.getId(),bookId);

        AjaxUtils.showInfo(resp,"加入购物车成功!","/jquery/findbookById.do?id="+bookId);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
